/** 退款申请 */
<template>
  <div class="add-refund-page">
    <el-card shadow="always">
      <div slot="header">
        <line-header title="退款详情"></line-header>
      </div>
      <div class="card-body">
        <el-form
          ref="form"
          :model="form"
          label-width="100px"
        >
          <el-form-item label="企业名称：" prop="eName" >
            <el-input
              disabled
              v-model="form.eName"
              placeholder="请输入公司名称"
            >{{this.form.eName}}</el-input>
          </el-form-item>
          <el-form-item label="银行账户：" prop="code">
            <el-input
              disabled
              v-model="form.code"
              placeholder="请输入对公账户"
            ></el-input>
          </el-form-item>
          <el-form-item label="开户行：" prop="bank">
            <el-input
              disabled
              v-model="form.bank"
              placeholder="请输入对公账户开户行"
            ></el-input>
          </el-form-item>
          <el-form-item label="姓名：" prop="receiver">
            <el-input v-model="form.receiver" disabled placeholder="请输入姓名"></el-input>
          </el-form-item>
          <el-form-item label="电话：" prop="contact">
            <el-input
              disabled
              v-model="form.contact"
              placeholder="请输入公司官方联系方式"
            ></el-input>
          </el-form-item>
          <el-form-item label="可退金额：">
            <el-input disabled v-model="balance" placeholder="" disabled></el-input>
          </el-form-item>
          <el-form-item label="退款金额：" prop="amount">
            <el-input
              disabled
              v-model="(form.amount)*0.01"
              placeholder="请输入金额"
            ></el-input>
          </el-form-item>
          <el-form-item label="审核描述：" >
            <el-input
              type="textarea"
              v-model="form.mark"
              placeholder="请输入审核描述"
              :disabled="form.result!=1"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <div class="buttom-btn-box">
              <template v-if="form.result>1||userInfo.role==2">
                <el-button  :type="form.result==3?'success':'danger'" disabled>{{getOstatus(form.result)}}</el-button>
              </template>
              <template v-else>
                  <el-button type="primary" @click="hkClickSubmit(3)">通过</el-button>
                  <el-button type="danger" @click="hkClickSubmit(4)">不通过</el-button>
              </template>

              <el-button type="primary" plain @click="hkClickCancel"
              >取消</el-button
              >
            </div>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
  import LineHeader from "@/components/line-header/index";
  import {mapGetters} from "vuex"
  import {trace} from "../../../utils/trace"
  import {isNull} from "../../../utils/tools";
  import { refundProcessList } from "@/utils/tools";
  import {refundResult} from "../../../api/finance";

  export default {
    components: { LineHeader },
    props: {},
    data() {
      return {
        form: {
          eName: "", //企业名称
          code: "", //银行账户
          bank: "", //开户行
          receiver: "", //姓名
          contact: "", //电话
          amount: "", //退款金额
          mark: "" //退款金额
        },

      };
    },
    watch: {},
    computed: {
      ...mapGetters([
        'balance',
        "userInfo"
      ])
    },
    methods: {
      getOstatus(status){
        trace("getOstatus",status)
        let obj = refundProcessList.find(item=>{
          return item.key == status+""
        })
        if(obj){
          return obj.label;
        }
        return "申请中"
      },
      async hkClickSubmit(result) {
        let {mark,id} = this.form;
        let res = await refundResult({result, mark,id});

        this.$router.push({path:"/finance/refund"})
      },
      hkClickCancel() {
        this.$router.back();
      }
    },
    created() {},
    mounted() {
      let query = this.$route.query;
      if (isNull(query) && isNull(query.info)) {
        return;
      }
      let obj = JSON.parse(decodeURIComponent(query.info));
      // this.form

      let form1 = {}
      this.$store.dispatch('finance/refundDetail', {id:obj.id}).then((data) => {
        trace("refundQuery-查询退款详情-data", data);
        form1.eName = data.eName;
        form1.code=data.code;
        form1.bank=data.bank;
        form1.receiver=data.receiver;
        form1.contact=data.contact;
        form1.amount=data.amount;
        form1.mark=data.mark;
        form1.id=data.id;
        form1.result=data.result;
        this.form =form1;
      })
        .catch((err) => {
          trace("查询退款列表-refundQuery-err", err)
        })
    }
  };
</script>
<style lang="scss" scoped>
  .card-body {
    max-width: 60%;
    margin: 0 auto;
    .buttom-btn-box{
      margin: 40px;
      text-align: center;
    }
  }
</style>

